//此函数执行会返回一个数组，数组里包含两个用户信息
function createUserList(){
  return[
    {
      userId: 1,
      username:'admin',
      password:'111111',
      desc:'平台管理员',
      roles:['平台管理员'],
      buttons:['cuser.detail'],
      routers:['home'],
      token:'Admin Token'
    }
  ]
}

//对外暴露两个接口
//登录的假接口
//获取用户信息的接口
export default [
  {
    url:'api/user/login',
    method:"post",
    respond:({body})=>{
      const {username,password} =body
      const checkUser=createUserList().find(
        (item)=>item.username===username && item.password===password,
      )
      if (!checkUser){
        return {code:201 , data:{message:'账号或密码不正确'}}
      }
      const {token}=checkUser
      return {code: 200,data: {token}}
    }

  },
  //获取用户信息
  {
    url:'api/user/info',
    method:'get',
    respond:(request)=>{
      const token=request.headers.token
      const checkUser=createUserList().find((item)=>{
        item.token===token
      })
      if (!checkUser){
        return{code: 201 , data: {message:'获取用户信息失败'}}
      }
      return {code: 200, data: {checkUser}}
    }
  }
]
